import * as ACTIONS from '../../actions/independent-practice/practiceAction';

/**
 * 数据视图默认状态
 * @type {Object}
 */
export const DEFAULT_DATA_STATE = {
	message: '',
	options: [{
		ID: ACTIONS.TypeOption.Practice,
		label: '自主练习'
	}, {
		ID: ACTIONS.TypeOption.Mission,
		label: '闯关'
	}, {
		ID: ACTIONS.TypeOption.PK,
		label: 'PK'
	}],
	optPracticeData: {
		isFetching: false,
		data: {}
	},
	optMissionData: {
		isFetching: false,
		data: {}
	},
	optPKData: {
		isFetching: false,
		data: {}
	}
};

export function practiceReducer(state = DEFAULT_DATA_STATE, action = {}) {
	let { type, payload } = action;
	switch(type) {
		case ACTIONS.GET_PRACTICE_DATA_REQUEST:
			return Object.assign({}, state, {
				[payload.key]: {
					isFetching: true,
					data: {}
				}
			});
		case ACTIONS.GET_PRACTICE_DATA_SUCCESS:
			return Object.assign({}, state, {
				[payload.key]: {
					isFetching: false,
					data: payload.data
				}
			});
		case ACTIONS.GET_PRACTICE_DATA_FAILURE:
			return Object.assign({}, state, {
				message: payload.message,
				[payload.key]: {
					isFetching: false,
					data: {}
				}
			});
		default:
			return state;
	}
};
